﻿using Oracle.DataAccess.Client;

namespace GeneratorSelections.Repository.DataBase
{
    static class DataDictionaryCommands
    {
        static string ColumnSelectTablesCommandText(string likeTableName)
        {
            return string.Format("Select table_name from all_tables where table_name like  '%{0}%' order by table_name", likeTableName);
        }
        static string ColumnSelectColumnsCommandText(string tableName)
        {
            return string.Format("Select column_name, data_type, data_length, nullable from all_tab_columns where table_name = '{0}' order by column_id", tableName);
        }

        static internal OracleCommand GetSelectTableCommand(string likeTableName=null)
        {
            var @select = ColumnSelectTablesCommandText(likeTableName);
            var cmd = new OracleCommand(@select) { Connection = ConnectionHandler.Instance.Connection };
            return cmd;
        }

        static internal OracleCommand GetSelectColumnsCommand(string tableName)
        {
            var @select = ColumnSelectColumnsCommandText(tableName);
            var cmd = new OracleCommand(@select) { Connection = ConnectionHandler.Instance.Connection };
            return cmd;
        }

    }
}
